/**
 * @file       PagingByPanelStrategy.cpp
 * @brief      TODO
 * @author     Huabo Zheng
 * @date       Jan 31, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#include "PagingByPanelStrategy.h"
#include "errorcode.h"
#include "PageInfo.h"
#include "Frame.h"

namespace NS_LCD_AFW
{

CPagingByPanelStrategy::CPagingByPanelStrategy()
{
}

CPagingByPanelStrategy::~CPagingByPanelStrategy()
{
}

int CPagingByPanelStrategy::calculateViewPort(
		const CFramePtrArray & framePtrArray, const CRect &parentRect,
		CPageInfo & pageResult)
{
	int curPage = pageResult.getCurPage();
	switch (pageResult.getDirection())
	{
	case CPageInfo::UP:
	{
		if (curPage <= 1)
		{
			pageResult.setNeedSwitchPage(false);
			return ERR_NO_CHANGE;
		}
		else
		{
			pageResult.setCurPage(curPage - 1);
			pageResult.setNeedSwitchPage(true);
		}
	}
		break;
	case CPageInfo::DOWN:
	{
		if (curPage >= pageResult.getTotalPage())
		{
			pageResult.setNeedSwitchPage(false);
			return ERR_NO_CHANGE;
		}
		else
		{
			pageResult.setCurPage(curPage + 1);
			pageResult.setNeedSwitchPage(true);
		}
	}
		break;
	default:
		break;
	}

	pageResult.setHightLightObjIndex(
			this->findNextHightlightableObjectIndex(framePtrArray,
					pageResult.getStartIndex(), pageResult.getEndIndex()));

	return ERR_SUCCESS;
}

} /* namespace NS_LCD_AFW */
